package com.youhome.wechat.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.response.*;
import com.youhome.service.service.ZillowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chen365 on 2018/07/24.
 */
@RestController
@Api(tags = "分析")
@RequestMapping("/analysis")
public class AnalysisController {
    @Autowired
    private ZillowService zillowService;

    @ApiOperation(value = "时间序列", notes = "时间序列", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "time", value = "年(默认0,0:表示所有,1：1年,2:2年)", paramType = "query")
    })
    @GetMapping(value = "/time/{type}/{zip}")
    public Object time(@PathVariable Integer type, @PathVariable String zip, @RequestParam(value = "t", defaultValue = "0") Integer t) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zillowService.getTimeSeries(type, zip, t));
    }

    @ApiOperation(value = "房租", notes = "房租", response = ZriResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/zri/{type}/{zip}")
    public Object zri(@PathVariable Integer type, @PathVariable String zip) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Zip_Zri_AllHomes_Summary(type, zip));
    }

    @ApiOperation(value = "房屋价格指数", notes = "房屋价格指数", response = ZhviResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/zhvi/{type}/{zip}")
    public Object zhvi(@PathVariable Integer type, @PathVariable String zip) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Zip_Zhvi_Summary_AllHomes(type, zip));
    }

    @ApiOperation(value = "买卖指数", notes = "买卖指数", response = BuyerSellerResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/buyerSeller/{type}/{zip}")
    public Object buyerSeller(@PathVariable Integer type, @PathVariable String zip) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Buyer_Seller_Index_Zip(type, zip));
    }

    @ApiOperation(value = "市场健康指数", notes = "市场健康指数", response = MarketHealthResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/marketHealth/{type}/{zip}")
    public Object marketHealth(@PathVariable Integer type, @PathVariable String zip) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Market_Health_Index_Zip(type, zip));
    }

    @ApiOperation(value = "租售比", notes = "租售比", response = BreakEvenPRResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/sale_rental_ratio/{type}/{zip}")
    public Object saleRentalRatio(@PathVariable Integer type, @PathVariable String zip) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Break_Even_PR(type, zip));
    }

    @ApiOperation(value = "租金涨幅百分比预测", notes = "租金涨幅百分比预测", response = ZriForecastPublicResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/zri_forecast_public/{type}/{zip}")
    public Object ZriForecastPublic(@PathVariable Integer type, @PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Zri_Forecast_Public(type, zip));
    }

    @ApiOperation(value = "贷款利息", notes = "贷款利息", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别(97:超大贷款利息,98:传统贷款利息)", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "t", value = "年(默认0:表示所有,1：1年,2:2年)", paramType = "query")
    })
    @GetMapping(value = "/loan_interest/{type}")
    public Object loanInterest(@PathVariable Integer type, @RequestParam(value = "t", defaultValue = "0") Integer t) {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_loan_interest(type, t));
    }

    @ApiOperation(value = "存量房统计", notes = "存量房统计", response = InventoryResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "format", value = "格式(count、pct)", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "year", value = "年(默认0:表示所有,1：1年,2:2年)", paramType = "query")

    })
    @GetMapping(value = "/inventory/{format}/{zip}")
    public Object inventory(@PathVariable String format, @PathVariable String zip, @RequestParam(value = "year", defaultValue = "0") Integer year) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_InventoryMeasure_Tiers_Metro_Public(format, zip, year));
    }


    @ApiOperation(value = "负资产率都会区统计", notes = "负资产率都会区统计", response = MetroNETiersResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path")
    })
    @GetMapping(value = "/negative_equity_metro/{type}/{zip}")
    public Object negativeEquityMetro(@PathVariable Integer type, @PathVariable String zip) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_Metro_NETiers(type, zip));
    }

    @ApiOperation(value = "负资产率按城市统计", notes = "负资产率按城市统计", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "zip", value = "邮编", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "int", name = "t", value = "年(默认0,0:表示所有,1：1年,2:2年)", paramType = "query")
    })
    @GetMapping(value = "/negative_equity_city/{type}/{zip}")
    public Object negativeEquityCity(@PathVariable Integer type, @PathVariable String zip, @RequestParam(value = "t", defaultValue = "0") Integer t) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zillowService.get_NegativeEquity_Public(type, zip, t));
    }
}
